package br.gov.cemaden.library.repository.alerta;

import br.gov.cemaden.library.model.alerta.Agencia;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;

/**
 *
 * @author alan
 */
public class AgenciaRepository {
    
    private final EntityManager em;
    
    public AgenciaRepository(EntityManager em){
        this.em = em;
    }
    
    public Agencia find(String nome){
        try{            
            Agencia agencia = em.createQuery("SELECT a FROM Agencia a"
                    + " WHERE a.nome = :nome", Agencia.class)
                    .setParameter("nome", nome)
                    .getSingleResult();
            
            return agencia;
        }
        catch(NoResultException ex){
            return null;
        }
    }
    
}
